package models;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;

import org.junit.Before;
import org.junit.Test;

public class testClient {
	
	private Client testClient;
		
	@Before
	public void setup() {
		testClient = new Client("Mark", "Spencer", "Myroad 16, 28240 MyCity", "06 390 2432 34", "markspancer@gmail.com");
	}
	
	/**
	 * Methode om te zien of de constructor van Client inderdaad een klant aanmaakt dat overeen stemt met de ingevoerde gegevens. 
	 */
	@Test
	public void testConstructor() {
		assertEquals("Mark", testClient.getGivenname());
		assertEquals("Spencer", testClient.getLastname());
		assertEquals("Myroad 16, 28240 MyCity", testClient.getAdress());
		assertEquals("06 390 2432 34", testClient.getPhone());
		assertEquals("markspancer@gmail.com", testClient.getEmail());
	}
	
	/**
	 * Methode om te checken of de methode die klanten vergelijkt om te controleren of ze identiek zijn, correct werkt.
	 */
	@Test
	public void testClientIsSimilarTo() {
		Client client = new Client("Mark", "berg", "Albergerbos", "023-5285463", "thuglife@hotmail.com");
		Client client_identical = new Client("Mark", "berg", "Albergerbos", "023-5285463", "thuglife@hotmail.com");
		Client client_similar = new Client("Mark", "berg", "Albergerbos", "023-5285463", "Stronglife@hotmail.com");
		Client client_different = new Client("Mark", "Spencer", "Myroad 16, 28240 MyCity", "06 390 2432 34", "markspancer@gmail.com");
		assertEquals(true, client.isSimilarTo(client_identical));
		assertEquals(true, client.isSimilarTo(client_similar));
		assertEquals(false, client.isSimilarTo(client_different));
	}
	
	@Test
	public void testSearchedMatch() {
		assertEquals(true, testClient.isSearchMatch("Mark"));
		assertEquals(true, testClient.isSearchMatch("myroad"));
		assertEquals(false,testClient.isSearchMatch("ownroad"));
	}
	
	@Test
	public void testDataHeaders() {
		String[] expected = {"givenname", "lastname", "address", "phone", "email"};
		assertEquals(Arrays.asList(expected), Arrays.asList(testClient.getDataHeaders()));
	}
	
	@Test
	public void testGetData() {
		String[] expected = {"Mark", "Spencer", "Myroad 16, 28240 MyCity", "06 390 2432 34", "markspancer@gmail.com"};
		assertEquals(Arrays.asList(expected), Arrays.asList(testClient.getData()));
	}
	
	@Test
	public void test_getDataString() {		
		testClient = new Client("Mark", "Spencer", "Myroad 16, 28240 MyCity", "06 390 2432 34", "markspancer@gmail.com");
		String expected = testClient.getDataString();
		assertEquals(
			"givenname='Mark', lastname='Spencer', address='Myroad 16, 28240 MyCity', phone='06 390 2432 34', email='markspancer@gmail.com'", 
			expected
		);
	}
	
	@Test
	public void test_getSelectString() {
		testClient = new Client("Mark", "Spencer", "Myroad 16, 28240 MyCity", "06 390 2432 34", "markspancer@gmail.com");
		String expected = testClient.getSelectString();
		assertEquals(
			"givenname='Mark' AND lastname='Spencer' AND address='Myroad 16, 28240 MyCity' AND phone='06 390 2432 34' AND email='markspancer@gmail.com'", 
			expected
		);
	}
	
	@Test
	public void test_EqualsAndHashCode() {
		Client client = new Client("Mark", "berg", "Albergerbos", "023-5285463", "thuglife@hotmail.com");
		Client client_identical = new Client("Mark", "berg", "Albergerbos", "023-5285463", "thuglife@hotmail.com");
		Client client_different = new Client("Mark", "Spencer", "Myroad 16, 28240 MyCity", "06 390 2432 34", "markspancer@gmail.com");
		
		assertEquals(client, client_identical);
		assertEquals(client.hashCode(), client_identical.hashCode());
		
		assertTrue(! client.equals(client_different));
		assertTrue(client.hashCode() != client_different.hashCode());
	}
	
}